<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<script type="text/javascript">
	function maintainerDate(cellvalue, options, rowObject) {

		return (rowObject.maintainerStartDate || "") + "~" + (rowObject.maintainerEndDate || "");
	}
	function formatCiName(rowObject) {
		return "<a href=\"javascript:isperp.openDialog({contentUrl:'configuration/ci/edit?readonly=true&id=" + rowObject.id + "'});\">" + rowObject.name + "</a>";
	}
	function formatSelector(rowObject, gridId) {
		return "<a href='javascript:void(0);' onclick=\""+gridId+"Selected('" + rowObject.id + "','"+rowObject.name+"')\">[选择]</a>";
	}
	function srcServiceGridSelected(id,name)
	{
	   $("#serviceCategoryName").val(name);
	   $("#serviceCategoryId").val(id);
	}
	function assAssectGridSelected(rowid) {
		var rowD = assAssectGrid.getRowData(rowid);
		$("#ciIdSelector").val(rowD.code);
		$("#ciId").val(rowD.id);
	}

	var reselectAsset = function() {

		$("#selectAssectGridGrid").show();
		$("#ciIdMsg").html("");
		$("#assAssetId").val("");
		$("#icdIncidentAssets").html("");

	};

	function customerCi_Onclick() {
		isperp.openDialog({
			id : "customerCiDiglog",
			onThisWindow : true,
			title : "选择关联资产",
			windowSize : "normal",
			contentUrl : "customer/customer/customerCiEdit?customerId=" + $("#hidCusUserCustomerId").val(),
			buttons : [ {
				text : "确定",
				"class" : "nui-mainbtn",
				click : function() {
					var $me = $(this);
					$me.find("iframe")[0].contentWindow.getSelectRow();
				}
			}, {
				text : "关闭",
				"class" : 'grey',
				click : function() {
					$(this).wijdialog("close");
				}
			} ]
		});

	}
</script>
<input type="hidden" id="cusUserId" name="cusUserId"
	value="${model.cusUserId }">
<table class="form-table">
	<c:if test="${model.status eq '退回' }">
		<tr>
			<td class="td1">退回原因：</td>
			<td class="td2" colspan="3" style="color:red">
				${model.backOpnion}</td>
		</tr>
	</c:if>
	<tr>
		<td class="td1">请求人：</td>
		<td class="td2"><input id=txtCusUserName name="cusUserName"
			class="hidden" type="text" maxlength="200" style="width:250px">
			<isperp:listSelector autocomplete="true" id="cusUserIdSelector"
				afterSelectEmpty="clearCusUser();" displayColumn="fullname"
				autocompleteUrl="customer/user/list" afterSelected="setCusUser(ids)"
				valueColumn="id" valueControlId="cusUserId"
				displayValueCssClass="required" url="customer/user/list">
				<isperp:column name="id" title="id" hidden="true"></isperp:column>
				<isperp:column name="fullname" title="名称" width="90">
				</isperp:column>
				<%-- <isperp:column name="type" title="类型" width="80">
				</isperp:column> --%>
				<isperp:column name="email" title="邮件" width="110">
				</isperp:column>
				<isperp:column name="tel" title="电话" width="90">
				</isperp:column>
				<isperp:column name="mobile" title="手机" width="90">
				</isperp:column>
				<isperp:column name="department_treenode_name_path" title="所属部门"
					width="110">
				</isperp:column>
			</isperp:listSelector> <a class="nui-txt-link" href="javascript:openCreateCusUser(1);">
				创建用户 </a><a class="nui-txt-link" href="javascript:openCreateCusUser(0);">更新用户信息
				</button>
		</td>
	</tr>
	<tr id="trUserInfo">
		<td class="td1"></td>
		<td class="td2" style="height:24px"><input
			id="hidCusUserCustomerId" type="hidden">电话：<label
			id="lbCusUserTel"></label>&nbsp;类型：<label id="lbCusUserType"></label>&nbsp;邮箱：<label
			id="lbCusUserEmail"></label>&nbsp;所在部门：<label
			id="lbCusUserDepartment"></label>&nbsp;联系地址：<label
			id="lbCusUserLinkaddress"></label></td>
	</tr>


	<tr>
		<td class="td1">联系人：</td>
		<td class="td2"><input id="linkmanName" name="linkmanName"
			value="${model.linkmanName }" class="" type="text" maxlength="50"
			style="width:249px"> <!--<input type="checkbox" id="areVip"
			name="areVip" value="1"> <label for="areVip">VIP</label> -->
		</td>
	</tr>

	<tr>
		<td class="td1">联系方式：</td>
		<td class="td2"><input id="linkmanPhone" name="linkmanPhone"
			value="${model.linkmanPhone }" class="" type="text" maxlength="50"
			style="width:249px"></td>
	</tr>
	
	<tr>
		<td class="td1">服务地址：</td>
		<td class="td2">
				<form:input path="areaDetail"  style="width:249px" placeholder="具体位置"/>
		</td>

	</tr> 

	<tr>
		<td class="td1">来源：</td>
		<td class="td2"><isperp:dictSelector typeCode="INCIDENT_SOURCE"
				name="source" id="source" hasEmptyValue="false" dataWidth="260px"
				dictCssClass="required" selectedValue="${model.source }"></isperp:dictSelector>
		</td>
	</tr>
	<tr>
		<td class="td1">事件性质：</td>
		<td class="td2"><isperp:dictSelector typeCode="INCIDENT_NATURE"
				name="incidentType" id="incidentType" hasEmptyValue="false"
				dictCssClass="required" dataWidth="260px"
				selectedValue="${model.incidentType }"></isperp:dictSelector>
		</td>
	</tr>
	<tr>
		<td class="td1">发生时间：</td>
		<td class="td2"><input id="happenTime" style="width:249px;"
			name="happenTime" type="datetime"
			value="<fmt:formatDate value="${model.happenTime}"
						pattern="yyyy-MM-dd HH:mm" />">
		</td>
	</tr>
	<%-- <tr>
		<td class="td1">期望完成时间：</td>
		<td class="td2"><input id="expectTime" style="width:249px;"
			name="expectTime" type="datetime"
			value="<fmt:formatDate value="${model.expectTime}"
						pattern="yyyy-MM-dd HH:mm" />">
		</td>
	</tr> --%>

	<tr>
		<td class="td1">发生频率：</td>
		<td class="td2"><isperp:dictSelector dataWidth="260px"
				typeCode="OCCURRENCE_FREQUENCY" id="occurrenceFrequency"
				name="occurrenceFrequency" hasEmptyValue="false"
				selectedValue="${model.occurrenceFrequency }"></isperp:dictSelector>
		</td>

	</tr>

	<tr>
		<td class="td1">事件标题：</td>
		<td class="td2"><input id="incidentTitle" name="title"
			value="${model.title }" class="required" type="text" maxlength="200"
			style="width:80%"></td>
	</tr>
	<tr>
		<td class="td1">事件描述：</td>
		<td class="td2"><textarea id="incidentDescription"
				class="required" style="height:50px;width:80%;" name="description">${model.description }</textarea>
		<c:if test="${model.source eq '邮件' }">
					<a href="javascript:void(0)" onclick="viewMail()"><br>查看原邮件内容</a>

				</c:if>
		</td>
	</tr>

	<tr> 
		<td class="td1">选择项目：</td>
		<td class="td2" colspan="3"><select id="incidentProjectId"
			data-width="260px"  class="search"
			name="projectId"></select>
		</td>
	<tr>
	<tr id="serviceCategoryTr" style="">
		<td class="td1">服务目录：</td>
		<td class="td2" colspan="3"><input type="hidden"
			id="serviceCategoryId" name="serviceCategoryId"
			value="${empty model.serviceCategoryId?'':model.serviceCategoryId }" />
			<isperp:categoryService
				displayValue="${empty model.serviceCategoryName?'':model.serviceCategoryName}"
				afterSelected="afterSelectServiceCategory()" multiselect="false"
				displayValueStyle="width:249px;" displayValueCssClass=""
				idFieldName="id" valueControlId="serviceCategoryId"
				id="serviceCategoryName" name="serviceCategoryName"></isperp:categoryService>
		</td>
	</tr>
	
	<%-- <tr id="assetTr">
		<td class="td1">关联资产：</td>
		<td class="td2"><input id="ciId" name="ciId" class="hidden"
			maxlength="200" value="${model.ciId}" style="width:250px"> <isperp:listSelector
				autocomplete="true" id="ciIdSelector"
				urlExtScript=" 'projectId='+getProjectId()"
				afterSelectEmpty="clearStCi();" displayColumn="code" name="ciCode"
				autocompleteDisplay="'【'+item.data['code']+'】'+item.data['name']"
				autocompleteUrl="configuration/ci/autocompletelist?a=1&" valueColumn="id"
				valueControlId="ciId" displayValue="${model.ciId }"
				displayValueCssStyle="width:249px" displayValueCssClass=""
				url="configuration/ci/listProjectCi?a=1&">
				<isperp:column name="id" title="id" hidden="true"></isperp:column>
				<isperp:column name="name" title="名称" width="90">
				</isperp:column>
				<isperp:column name="code" title="编号" width="80">
				</isperp:column>
				<isperp:column name="assetCode" title="序列号" width="80">
				</isperp:column>
				<isperp:column name="status" title="状态" width="80">
				</isperp:column>

			</isperp:listSelector> <a class="nui-txt-link" style="margin-left:-7px" onclick="viewCi()">查看</a>
			  </td>
	</tr> --%>
	
	<tr>
		<td class="td1">解决方式：</td>
		<td class="td2" colspan="3"><isperp:dictSelector
				typeCode="INCIDENT_SOLUTIONWAY" name="solutionWay" dataWidth="260px"
				id="solutionWay" hasEmptyValue="false"
				selectedValue="${model.solutionWay}"></isperp:dictSelector></td>
	</tr>
	<tr>
		<td class="td1">附件：</td>
		<td class="td2"><isperp:uploader sourceId="${model.id }"
				id="incidentFiles"></isperp:uploader>
		</td>
	</tr>

</table>
<div id="createCusUserDialog" title="创建用户"
	style="display:none;-webkit-overflow-scrolling:touch; overflow:auto;">
	<iframe id="createCusUserIframe" src=""
		style="width:100%;height:90%;;border:none"></iframe>
</div>

<script type="text/javascript">
    function getProjectId()
    {
      return $("#incidentProjectId").val();
    }

	function clearServiceCategory() {
		$("#serviceCategoryName").val("");
		$("#serviceCategoryId").val("");
	}
	function afterSelectServiceCategory() {
		return true;
	}

	function viewCi() {
		if ($("#ciId").val() == "" || $("#ciId").val() == undefined) {
			return false;
		} else {
			var ciId = $("#ciId").val();
			isperp.openDialog({
				contentUrl : "configuration/ci/edit?id=" + ciId + "&readonly=true"
			});
		}
	}

	function icdCategory_afterSelected(treeNode) {
		$("#incidentType").val(treeNode.incidentType);
		$("#performancePoint").val(treeNode.performancePoint);
		$("#incidentType").trigger('chosen:updated');
	}
	function changeProject() {
		if (projectMemberGrid) {
		    var projectId=$("#incidentProjectId").val();
		    if(projectId)
		    {
		      searchProjectMember();
		      searchService(projectId,"");
		    }
			   
		}
	}

	function resetPriorityName() {
		var $urgencyName = $("#urgencyName option:selected"), urgencyNameCode = parseInt($urgencyName.data("code"));
		var $effectName = $("#effectName option:selected"), effectNameCode = parseInt($effectName.data("code"));

		var ueVal = urgencyNameCode + effectNameCode;

		var $priorityName = $("#priorityName"), $priorityNameOptions = $("#priorityName option");

		for ( var i = 0; i < $priorityNameOptions.length; i++) {
			var $item = $($priorityNameOptions[i]), code = parseInt($item.data("code"));

			if (ueVal >= code) {
				$priorityName.val($item.val());
				$("#priorityName").trigger("chosen:updated");
				return;
			}
		}

	}

	var createCusUserDlg = $("#createCusUserDialog").dialog({
		modal : true,
		autoOpen : false,
		width : 500,
		height : 520,
		open : function(event, ui) {
			$("#createCusUserId").val("");

		},
		buttons : {
			保存 : function() {
				var $me = $(this);
				isperp.getWindow("createCusUserIframe").sumbitCusUserForm(function(id) {
					$me.dialog("close");
					$("#cusUserId").val(id);
					setCusUser(id);
				});

			}

		}
	});
	//新增用户
	function openCreateCusUser(isNew) {
		var title;
		if (isNew) {
			title = "创建用户";
			$("#createCusUserIframe").attr("src", "customer/user/createUserEdit");
		} else {
			title = "更新用户信息";
			var userId = $("#cusUserId").val();
			$("#createCusUserIframe").attr("src", "customer/user/createUserEdit?id=" + userId);
		}

		createCusUserDlg.dialog({
			title : title
		});
		createCusUserDlg.dialog("open");

	}

	function clearCusUser() {

		$("#cusUserId").val("");
		$("#txtCusUserName").val("");
		$("#cusUserIdSelector").val("");
		$("#lbCusUserTel").html("");
		$("#lbCusUserCustomer").html("");
		$("#hidCusUserCustomerId").val("");
		$("#lbCusUserType").html("");
		$("#lbCusUserEmail").html("");
		$("#lbCusUserDepartment").html("");
		$("#lbCusUserLinkaddress").html("");

		$("#lbCusIdCard").html("");
		$("#lbCusBankCardNumber").html("");
	}

	//显示用户详细资料，并带出用户关联的项目信息以及其关联的所有资产
	function setCusUser(userId) {
		userId = userId || "${model.cusUserId}";
		if (userId) {

			//带出用户历史事件
			var tid = '${model.id}';
			try {

				userIncidentHistoryGrid.jqGrid.setGridParam({
					url : "incident/incident/listByCusUser?cusUserId=" + userId
				});

				userIncidentHistoryGrid.search();
			} catch (e) {

			}

			$.getJSON("customer/user/getDetail?id=" + userId + "&icdId=" + tid, function(data) {

				if (data) {

					$("#trUserInfo").show();
					$("#cusUserId").val(data.id);
					$("#txtCusUserName").val(data.fullname);

					if ('${modelEdit}' != "true") {
					    var phone=data.mobile;
					    if(data.tel)
					       phone=phone+"/"+data.tel;
						$("#linkmanPhone").val(phone);
						$("#linkmanName").val(data.fullname);
					}

					$("#cusUserIdSelector").val(data.fullname);

					$("#lbCusUserCustomer").html(data.customer_name);
					var tm = "";
					if (data.mobile)
						tm += data.mobile
					if (data.tel)
						tm += "/" + data.tel;

					$("#lbCusUserTel").html(tm);
					/* if (data.type != undefined) {
						$("#lbCusUserType").html(data.type);
						if (data.type == "VIP") {
							document.getElementById("areVip").checked = true;
						} else {
							document.getElementById("areVip").checked = false;
						}

					} else
						$("#lbCusUserType").html(""); */
					if (data.mobile_short != undefined)
						$("#lbCusUserMobileShort").html(data.mobile_short);
					else
						$("#lbCusUserMobileShort").html("");

					if (data.code != undefined)
						$("#lbCusUserName").html(data.code);
					else if (data.name != undefined)
						$("#lbCusUserName").html(data.name);
					else
						$("#lbCusUserName").html("");

					if (data.email != undefined)
						$("#lbCusUserEmail").html(data.email);
					else
						$("#lbCusUserEmail").html("");
					if (data.department_treenode_name_path != undefined)
						$("#lbCusUserDepartment").html(data.department_treenode_name_path);
					else
						$("#lbCusUserDepartment").html("");
					if (data.address != undefined)
						$("#lbCusUserLinkaddress").html(data.address);
					else
						$("#lbCusUserLinkaddress").html("");
				}
				//ciUseRelationGrid.reload();
			});

			$.getJSON("customer/user/listProjects?userId=" + userId, function(data) {
				$("#incidentProjectId").empty();
				if (data[0]) {
					$(data).each(function(index, item) {
						if ("${model.projectId}" == item.id) {
							$("#incidentProjectId").append('<option  selected="selected" value="'+item.id+'">' + item.name + '</option>');
						} else {
							if (data.length == 1) {
								$("#incidentProjectId").append('<option value="'+item.id+'" selected="selected">' + item.name + '</option>');
							} else {
								$("#incidentProjectId").append('<option value="'+item.id+'">' + item.name + '</option>');
								$("#incidentProjectId").val("");
							}

						}
					});
				}

				$("#incidentProjectId").trigger("chosen:updated");
				changeProject();
			});

		}

	};
	function viewMail() {
		var id = '${model.id}';
		isperp.openDialog({
			windowSize : "normal",
			contentUrl : "incident/incident/viewMail?id=${model.id}"
		});
	}

	resetPriorityName();
	
</script>


